<template>
	<view>
		<template v-if='loading'>
			<view v-for="(item,index) in 5" :key="index">
				<view class=" Skeleton" style="height: 30rpx;" />
				<view class="activeContent" style="border: none;">
					<view>
						<album :loading='loading' />
					</view>
					<view class=" Skeleton" style="height: 30rpx;margin-top: 20rpx;" />
				</view>
			</view>
		</template>
		<template v-else>
			<view class="activeBox" v-for="(item,index) in list" :key="index">
				<view class="created_at">
					<u-avatar mode='aspectFill' :src='item.user.avatar' size='80rpx' />
					<view style="margin:0 10rpx;flex: 1;">
						<view>
							{{item.user.nick_name}}·{{item.created_at | changeTime}}
						</view>
					</view>
				</view>
				<view class="activeContent">
					<view class="content">
						<view style="margin:  0 0 10rpx;">
							{{item.title}}
						</view>
						<view style="position: relative;">
							<album :ref='`album${index}`' :imageList='item.images'
								:video='item.videos.map(imageItem=>imageItem.url)' :index='index'
								:playIndex='playIndex' />
						</view>
						<view class="rewardsBox">
							<view v-for="(rewardItem,index) in item.wish_reward" :key="index">
								{{rewardItem.title}}
								<text class="rewardPoint">{{rewardItem.value}}</text>
							</view>
						</view>

						<view v-for="recordItem in item.redpacket_record" :key="recordItem.id" class="userBox">
							<u-avatar :src='recordItem.sender.avatar' />
							<view>
								<view>
									{{recordItem.sender.nick_name}}
								</view>
								<view>
									{{recordItem.blessing_words}}
								</view>
							</view>
							<view>
								<u-icon name='red-packet-fill' :label='recordItem.red_packet' labelColor='red'
									color='red' />
							</view>
							<view class="ml20 moreBox">
								<view>
									<view style="flex: 1;">
										<u-icon v-if="item.isThumbsuped" name='thumb-up-fill' color='#fff' size='30rpx'
											:label='item.thumbsup_count>99?"99+":item.thumbsup_count' labelSize='24rpx'
											labelColor='#fff' @click="Thumbsup(item)"/>

										<u-icon v-else name='thumb-up' color='#fff' size='30rpx'
											:label='item.thumbsup_count>99?"99+":item.thumbsup_count' labelSize='24rpx'
											labelColor='#fff'  @click="Thumbsup(item)"/>
									</view>
									<view style="flex: 1;">
										<u-icon name='chat' color='#fff' size='30rpx' label='评论' labelSize='24rpx'
											labelColor='#fff'  @click="openComment(item.id)" />
									</view>

									<view class="info-panel-triple">

									</view>
								</view>
								<u-icon name='more-dot-fill' />
							</view>
						</view>

					</view>
				</view>
			</view>
		</template>
		<root-portal>
			<comment v-if="commentShow" :show='commentShow' @show_fun='commentShow=!commentShow' :commentId='run_id' />
		</root-portal>
	</view>
</template>

<script>
	import {
		format
	} from "timeago.js";
	import album from '@/components/album.vue';
	import comment from './comment'
	export default {
		components: {
			album,
			comment
		},
		props: ['list', 'loading', 'playIndex', 'weight', 'start_at'],
		data() {
			return {
				run_id: null,
				commentShow: false,
				d: false,
				selectItem: {},
				show: false,
				user: uni.getStorageSync("user"),
			}
		},
		mounted() {},
		methods: {
			Thumbsup(item) {
				if (item.isThumbsuped) {
					uni.$u.toast('取消点赞')
				item.thumbsup_count--
				} else {
					uni.$u.toast('点赞成功')
				item.thumbsup_count++
				}
				item.isThumbsuped = !item.isThumbsuped
				this.$api.Thumbsup.Thumbsup('run', item.id)
			
			},
			openComment(id) {
				this.run_id = id
				console.log(id)
				this.commentShow = true
			},
			getTimeDifferenceInDays(timestamp1, timestamp2) {
				// 将时间戳转换为日期对象
				const date1 = new Date(timestamp1);
				const date2 = new Date(timestamp2);

				// 计算两个日期之间的毫秒差
				const timeDifferenceInMilliseconds = Math.abs(date2 - date1);

				// 将毫秒转换为天数，一天有 24 * 60 * 60 * 1000 毫秒
				const oneDayInMilliseconds = 24 * 60 * 60 * 1000;
				const differenceInDays = Math.ceil(timeDifferenceInMilliseconds / oneDayInMilliseconds);

				return differenceInDays - 1;
			},
			formatFun(item) {
				return format(item, "zh_CN")
			},
		}
	}
</script>

<style lang="scss" scoped>
	.created_at {
		font-size: 28rpx;
		display: flex;
		align-items: center;
		margin-right: 40rpx;
		justify-content: space-between;

	}

	.activeContent {
		padding: 0 0 0 35rpx;
		margin: 10rpx 0 10rpx 35rpx;
		border-left: 1rpx dashed #bbb;

		>.content {
			box-shadow: 0 0 10rpx #ddd;
			margin-right: 20rpx;
			padding: 20rpx;
			border-radius: 8rpx;
			background-color: #fff;
		}
	}



	.userBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 20rpx;
		padding: 0 0 10rpx;
		border-bottom: 1rpx solid #ddd;

		>view:nth-child(2) {
			flex: 0.98;
		}
	}

	.point {
		position: absolute;
		z-index: 11;
		padding: 20rpx;
		background: rgba(0, 0, 0, 0.3);
		top: 20rpx;
		left: 20rpx;
		color: #fff;
		border-radius: 8rpx;
	}

	.rewardsBox {
		display: flex;
		flex-wrap: wrap;

		>view {
			padding: 10rpx 20rpx;
			border-radius: 100rpx;
			border: 1rpx solid #ddd;
			position: relative;
			margin-right: 10rpx;
			margin-bottom: 10rpx;
		}

		.rewardPoint {
			border-radius: 100rpx;
			color: #fff;
			background: rgba(0, 0, 0, 0.3);
			position: absolute;
			top: -10rpx;
			right: -10rpx;
			padding: 5rpx;
		}
	}

	.moreBox:hover {
		>view {
			display: flex;
		}
	}

	.moreBox {
		position: relative;



		>view {
			.info-panel-triple {
				width: 0;
				height: 0;
				border: 8px solid transparent;
				border-bottom-color: black;
				position: absolute;
				top: -16px;
				right: 12rpx;
			}

			position: absolute;
			display: none;
			align-items: center;
			box-sizing: border-box;
			border-radius: 8rpx;
			padding: 10rpx;
			top: 40rpx;
			left: -167rpx;
			min-width: 202rpx;
			background-color: rgb(0, 0, 0);

			>view:first-child {
				padding-right: 10rpx;
				margin-right: 10rpx;
				border-right: 1rpx solid #fff;
			}
		}
	}
</style>